﻿using famails.bus;
using famails.common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace famails
{
    public partial class famails : System.Web.UI.MasterPage
    {
        public baivietBUS baivietBus = new baivietBUS();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadHeader();
                LoadFooter();
            }
        }
        private void LoadHeader()
        {
            string sql = "SELECT * FROM tblConfig Where idGroup='header'";
            SqlCommand cmd = new SqlCommand(sql, ConnectionData._MyConnection);
            cmd.CommandType = CommandType.Text;
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable table = new DataTable();
            adapter.Fill(table);
            cmd.Dispose();
            rptListPost.DataSource = table;
            rptListPost.DataBind();
            rptListPost2.DataSource = table;
            rptListPost2.DataBind();
        }
        private void LoadFooter()
        {
            string sql = "Select * From tblGroupConfig Where isShow='True' except (Select * From tblGroupConfig Where idGroup='mainpost' OR idGroup='header'AND isShow='True' )";
            SqlCommand cmd = new SqlCommand(sql, ConnectionData._MyConnection);
            cmd.CommandType = CommandType.Text;
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable table = new DataTable();
            adapter.Fill(table);
            cmd.Dispose();
            DataTable dt;
            foreach (DataRow dr in table.Rows)
            {
                string idgroup = dr["idGroup"].ToString();
                SqlCommand cmd2 = new SqlCommand("Select * From tblGroupConfig Where idGroup='" + idgroup + "'", ConnectionData._MyConnection);
                cmd2.CommandType = CommandType.Text;
                SqlDataAdapter da = new SqlDataAdapter(cmd2);
                dt = new DataTable();
                da.Fill(dt);
            }
            rptFooter.DataSource = table;
            rptFooter.DataBind();
        }
    }
}